clear all
set more off

cd "D:/Dropbox/coauthors/AMT_Bisbee_Larson/bisbee_larson_replication_final"

********************************************************************************
* File Name: protest_replication.do
* 
* Input Files: 	final_data_clean.dta
* Output Files: prot-simple.dta
*               prot_join_all.tex
*				prot_inform_all.tex
*
* Purpose: The purpose of this file is to (1) prepare the prot-simple.dta file
* for analysis in the protest-results.R script and (2) to estimate non-causal 
* relationships between tie dimensions and protest behaviors. The latter .tex 
* files comprise Tables 2 and 3 in the Supporting Information.
********************************************************************************

use "./tools/final_data_clean.dta", clear
foreach var of varlist interaction* {
	replace `var' = `var' * -1
}

foreach var of varlist interaction* jobsearch_* personalgain_* grpgain_* contribute_* garner_* pers_*_synth_* prof_*_synth_* seat_synth2_* {
	g `var'_rob = 0
	tab `var'
	replace `var'_rob = 1 if `var' == -1 | `var' == 2
}


//keep prot_invite prot_join prot_peace *_inform_* *_prompt_* cem_weights strata std_* introvert dem* online tie_synth* interaction_*
foreach dim in "interaction""jobsearch""contribute""garner""personalgain""grpgain""homo_pol""homo_rel""homo_educ""homo_ls""pers_cris_synth""pers_succ_synth""prof_cris_synth""prof_succ_synth""seat_synth2_lst""seat_synth2_mst" {
	g prot_dim_`dim' = .
	foreach tie in "weakest""weak""strong""strongest""clique"  {
		replace prot_dim_`dim' = `dim'_`tie' if prot_invite == "`tie'"
	}
}

foreach dim in "interaction""jobsearch""contribute""garner""personalgain""grpgain""pers_cris_synth""pers_succ_synth""prof_cris_synth""prof_succ_synth""seat_synth2_lst""seat_synth2_mst" {
	g prot_dim_`dim'_rob = .
	foreach tie in "weakest""weak""strong""strongest""clique"  {
		replace prot_dim_`dim'_rob = `dim'_`tie'_rob if prot_invite == "`tie'"
	}
}


foreach tie in "weakest""weak""strong""strongest""clique" {
	capture gen `tie'_dum = 0
	replace `tie'_dum = 1 if prot_invite == "`tie'"
}

keep prot_join prot_dim_* dem2* online prot_peace prot_invite introvert *_dum

encode prot_invite, g(prot_inv_num)

foreach var of varlist prot_dim* {
	sum `var'
	replace `var' = (`var' - r(mean))/r(sd)
}

saveold "./protests/prot-simple.dta", replace

* Non-causal estimation on the full data
use "./tools/final_data_clean.dta", clear
g ind = _n
keep prot_prompt_* prot_inform_* tie_synth_* std_interaction_* std_jobsearch_* std_contribute_* std_garner_* std_personalgain_* ///
	std_grpgain_* std_*_*_synth_* std_donate_* std_tie_synth_* std_homo_*_* ind tie* prot_peace* online cem_weights strata ///
	dem2_* introvert std_seat_*
reshape long prot_prompt_ prot_inform_ tie_synth_ std_interaction_ std_jobsearch_ std_contribute_ std_garner_ std_personalgain_ ///
std_grpgain_ std_prof_cris_synth_ std_prof_succ_synth_ std_pers_cris_synth_ std_pers_succ_synth_ std_donate_ std_tie_synth_ ///
std_homo_pol_ std_homo_rel_ std_homo_educ_ std_homo_ls_ std_seat_synth2_lst_ std_seat_synth2_mst_, i(ind) j(tie) string
replace std_interaction_ = std_interaction_ * -1
tabulate(tie), g(tie_dum)
ren tie_dum1 clique_dum
ren tie_dum2 strong_dum
ren tie_dum3 strongest_dum
ren tie_dum4 weak_dum
ren tie_dum5 weakest_dum

label var std_homo_pol_ "Political Hom."
label var prot_peace "Peaceful Protest"
label var online "Online"
label var std_jobsearch_ "Job Search"
label var std_contribute_ "Contrib. to Entrep."
label var std_garner_ "Garner Conts."
label var std_personalgain_ "Personal Gain (\% \$100)"
label var std_grpgain_ "Group Gain (\% \$100)"
label var std_homo_rel_ "Religious Hom."
label var std_homo_educ_ "Education Hom."
label var std_homo_ls_ "Class Hom."
label var std_pers_cris_synth_ "Pers. Crisis"
label var std_pers_succ_synth_ "Pers. Success"
label var std_prof_cris_synth_ "Prof. Crisis"
label var std_prof_succ_synth_ "Prof. Success"
label var weakest_dum "Weakest Tie"
label var strong_dum "Strong Tie"
label var strongest_dum "Strongest Tie"
label var weak_dum "Weak Tie"
label var std_interaction_ "Pref. Interaction"
label var std_seat_synth2_lst_ "Least in Common"
label var std_seat_synth2_mst_ "Most in Common"

foreach var of varlist std_* {
	sum `var'
	if `r(N)' == 0 {
	di "`var'"
	drop `var' 
	}
}

replace std_seat_synth2_mst_ = std_seat_synth2_mst_*-1
replace std_tie_synth_ = std_tie_synth_*-1
 
drop std_tie_synth_ std_donate_ std_homo_life_skills
replace std_interaction_ = -1*std_interaction_
ren clique_dum clique_dummy

// Regressions on prompting the protest: full data
reg prot_prompt_ std_homo_pol_, robust // bivariate
eststo I
reg prot_prompt_ std_homo_pol_ introvert dem2_educ_low dem2_adult dem2_fam_mar dem2_fam_sing, robust // controls
eststo II
reg prot_prompt_ std_homo_pol_ introvert dem2_educ_low dem2_adult dem2_fam_mar dem2_fam_sing prot_peace online, robust // controls
eststo III
reg prot_prompt_ std_homo_pol_ prot_peace online [aw=cem_weights], robust // controls
eststo IV
reg prot_prompt_ std_* prot_peace online [aw=cem_weights], robust // controls
eststo V
reg prot_prompt_ *_dum std_* prot_peace online [aw=cem_weights], robust // controls
eststo VI
sem (prot_prompt_ <- *_dum std_* introvert online prot_peace)
eststo VII

esttab I II III IV V VI VII using "./2_Tables/prot_join_all.tex", replace ///
cells(b(star fmt(2)) se(par fmt(2))) fragment stats(N,labels(N) fmt(0 2)) starlevel(* .10 ** .05 *** .01) ///
booktabs nolz label noabb wrap varwidth(50) nodepvars ///
mtitles("Biv." "Cont. 1" "Cont. 2" "CEM 1" "CEM 2""Full""SEM") keep(std_* *_dum prot_peace online)

// Regressions on informing of the protest
reg prot_inform_ std_homo_pol_, robust // bivariate
eststo I
reg prot_inform_ std_homo_pol_ introvert dem2_educ_low dem2_adult dem2_fam_mar dem2_fam_sing, robust // controls
eststo II
reg prot_inform_ std_homo_pol_ introvert dem2_educ_low dem2_adult dem2_fam_mar dem2_fam_sing prot_peace online, robust // controls
eststo III
reg prot_inform_ std_homo_pol_ prot_peace online [aw=cem_weights], robust // controls
eststo IV
reg prot_inform_ std_* prot_peace online [aw=cem_weights], robust // controls
eststo V
reg prot_inform_ *_dum std_* prot_peace online [aw=cem_weights], robust // controls
eststo VI
sem (prot_inform_ <- *_dum std_* introvert online prot_peace)
eststo VII

esttab I II III IV V VI VII using "./2_Tables/prot_inform_all.tex", replace ///
cells(b(star fmt(2)) se(par fmt(2))) fragment stats(N,labels(N) fmt(0 2)) starlevel(* .10 ** .05 *** .01) ///
booktabs nolz label noabb wrap varwidth(50) nodepvars ///
mtitles("Biv." "Cont. 1" "Cont. 2" "CEM 1" "CEM 2""Full""SEM") keep(std_* *_dum prot_peace online)
